<?php

class Catmgame extends AppModel {

    var $alias = 'Catmgame';
    var $name = 'Catmgame';
    var $useTable = 'mgame_categories';
    var $hasMany = array(
        'Mgame' => array(
            'className' => 'Mgame',
            'foreignKey' => 'cat_id',
            'dependent' => true,
        )
    );

    function paginateCount($conditions = null, $recursive = 0, $extra = array()) {
        $parameters = compact('conditions');
        $this->recursive = $recursive;
        $count = $this->find('count', array_merge($parameters, $extra));
        if (isset($extra['group'])) {
            $count = $this->getAffectedRows();
        }
        return $count;
    }
    function setListCategoryCache(){
        $cacheName  =   'list-catmgame-info';
        $data = $this->find('all', array(
                    'conditions' => array('Catmgame.published' => '1'),
                    'fields' => 'Catmgame.id, Catmgame.title, Catmgame.alias, Catmgame.total_games',
                    'recursive'=>   -1
        ));
        $cat_list   =   array();
        foreach($data AS $row){
            $cat_list[$row['Catmgame']['id']]    =   $row['Catmgame'];
        }
        Cache::write($cacheName, $cat_list, 'mgames');
    }
    function getListAll() {
        
        $data = $this->find('list', array(
                    'fields' => 'Catmgame.id, Catmgame.title',
                ));
        
        return $data;
    }
}

?>
